Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make AVP decoding goroutine-safe #186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

higebu
Copy link
Contributor

@higebu higebu commented Nov 24, 2023

Fixes #140

A read buffer will be reused when diam.ReadMessage() finishes. However, the byte slice in the read buffer will remain. This is because the byte slice is not copied during the decoding of AVPs.
Therefore, when trying to read diam.Message.AVP after diam.ReadMessage() has completed, a race condition occurs if the read buffer has already been reused.

func ReadMessage(reader io.Reader, dictionary *dict.Parser) (*Message, error) {
buf := newReaderBuffer()
defer putReaderBuffer(buf)
m := &Message{dictionary: dictionary}
cmd, stream, err := m.readHeader(reader, buf)
if err != nil {
return nil, err
}
m.stream = stream
if err = m.readBody(reader, buf, cmd, stream); err != nil {
return nil, err
}
return m, nil
}

@higebu higebu changed the title Copy byte slice in datatype decoding Make AVP decoding goroutine-safe Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Race Condition
1 participant